# -*- coding: UTF-8 -*-
'''
@学习网站      ：https://www.python-office.com
@读者群     ：http://www.python4office.cn/wechat-group/
@作者  ：B站/抖音/微博/小红书/公众号，都叫：程序员晚枫，微信：CoderWanFeng
@代码日期    ：2024/5/5 22:00 
@本段代码的视频说明     ：
'''

import poocr

SecretId = 'AKIDztbwHThnrtr7IHUm3Pugeq0vpfbeq4GY'
SecretKey = ''

# res = poocr.ocr.VatInvoiceOCR(img_path=r'./img.png', id=SecretId, key=SecretKey)
pdf_path = r'C:\Users\Lenovo\Desktop\temp\12365.pdf'
img_path = r'C:\Users\Lenovo\Desktop\temp\Snipaste_2024-05-08_21-32-42.jpg'

poocr.ocr2excel.VatInvoiceOCR2Excel(input_path=pdf_path, id=SecretId, key=SecretKey, file_name=True)
# pdf_res = poocr.ocr.VatInvoiceOCR(pdf_path=pdf_path, id=SecretId, key=SecretKey)
# print(pdf_res)
# img_res = poocr.ocr.VatInvoiceOCR(img_path=img_path, id=SecretId, key=SecretKey)
# print(img_res)
# print(res)
# poocr.ocr2excel.VatInvoiceOCR2Excel(img_path=r'')

"""
调用API直接翻译
{"VatInvoiceInfos": [{"Name": "销售方识别号", "Value": "911201103409033300", "Polygon": {"LeftTop": {"X": 373, "Y": 822}, "RightTop": {"X": 612, "Y": 822}, "RightBottom": {"X": 612, "Y": 845}, "LeftBottom": {"X": 373, "Y": 845}}}, {"Name": "销售方名称", "Value": "深圳腾讯游戏有限公司", "Polygon": {"LeftTop": {"X": 373, "Y": 785}, "RightTop": {"X": 615, "Y": 785}, "RightBottom": {"X": 615, "Y": 811}, "LeftBottom": {"X": 373, "Y": 811}}}, {"Name": "购买方识别号", "Value": "91440300MA55UJ6L44", "Polygon": {"LeftTop": {"X": 376, "Y": 266}, "RightTop": {"X": 649, "Y": 266}, "RightBottom": {"X": 649, "Y": 290}, "LeftBottom": {"X": 376, "Y": 290}}}, {"Name": "购买方名称", "Value": "腾讯优图有限公司", "Polygon": {"LeftTop": {"X": 376, "Y": 228}, "RightTop": {"X": 571, "Y": 228}, "RightBottom": {"X": 571, "Y": 254}, "LeftBottom": {"X": 376, "Y": 254}}}, {"Name": "发票名称", "Value": "天津增值税电子普通发票", "Polygon": {"LeftTop": {"X": 606, "Y": 57}, "RightTop": {"X": 1182, "Y": 57}, "RightBottom": {"X": 1182, "Y": 111}, "LeftBottom": {"X": 606, "Y": 111}}}, {"Name": "发票代码", "Value": "012001100311", "Polygon": {"LeftTop": {"X": 1342, "Y": 59}, "RightTop": {"X": 1499, "Y": 59}, "RightBottom": {"X": 1499, "Y": 82}, "LeftBottom": {"X": 1342, "Y": 82}}}, {"Name": "发票号码", "Value": "No63591128", "Polygon": {"LeftTop": {"X": 1342, "Y": 99}, "RightTop": {"X": 1450, "Y": 99}, "RightBottom": {"X": 1450, "Y": 120}, "LeftBottom": {"X": 1342, "Y": 120}}}, {"Name": "开票日期", "Value": "2019年06月16日", "Polygon": {"LeftTop": {"X": 1341, "Y": 135}, "RightTop": {"X": 1506, "Y": 135}, "RightBottom": {"X": 1506, "Y": 159}, "LeftBottom": {"X": 1341, "Y": 159}}}, {"Name": "校验码", "Value": "04656054380312409795", "Polygon": {"LeftTop": {"X": 1341, "Y": 173}, "RightTop": {"X": 1627, "Y": 173}, "RightBottom": {"X": 1627, "Y": 197}, "LeftBottom": {"X": 1341, "Y": 197}}}, {"Name": "机器编号", "Value": "499099606262", "Polygon": {"LeftTop": {"X": 268, "Y": 185}, "RightTop": {"X": 429, "Y": 185}, "RightBottom": {"X": 429, "Y": 207}, "LeftBottom": {"X": 268, "Y": 207}}}, {"Name": "密码区1", "Value": "033-<<>7>616<-4+*-+4/5230604", "Polygon": {"LeftTop": {"X": 1061, "Y": 232}, "RightTop": {"X": 1640, "Y": 232}, "RightBottom": {"X": 1640, "Y": 258}, "LeftBottom": {"X": 1061, "Y": 258}}}, {"Name": "密码区2", "Value": "*/78+740454724/0<34*9/>61856", "Polygon": {"LeftTop": {"X": 1061, "Y": 268}, "RightTop": {"X": 1639, "Y": 268}, "RightBottom": {"X": 1639, "Y": 295}, "LeftBottom": {"X": 1061, "Y": 295}}}, {"Name": "密码区3", "Value": "29/-0651-2*91440-47386<535<5", "Polygon": {"LeftTop": {"X": 1061, "Y": 306}, "RightTop": {"X": 1640, "Y": 306}, "RightBottom": {"X": 1640, "Y": 333}, "LeftBottom": {"X": 1061, "Y": 333}}}, {"Name": "密码区4", "Value": "92<<9-9+-601452319091>67>--7", "Polygon": {"LeftTop": {"X": 1061, "Y": 343}, "RightTop": {"X": 1640, "Y": 343}, "RightBottom": {"X": 1640, "Y": 369}, "LeftBottom": {"X": 1061, "Y": 369}}}, {"Name": "规格型号", "Value": "无", "Polygon": {"LeftTop": {"X": 619, "Y": 426}, "RightTop": {"X": 643, "Y": 426}, "RightBottom": {"X": 643, "Y": 451}, "LeftBottom": {"X": 619, "Y": 451}}}, {"Name": "单位", "Value": "次", "Polygon": {"LeftTop": {"X": 762, "Y": 424}, "RightTop": {"X": 786, "Y": 424}, "RightBottom": {"X": 786, "Y": 451}, "LeftBottom": {"X": 762, "Y": 451}}}, {"Name": "数量", "Value": "1", "Polygon": {"LeftTop": {"X": 887, "Y": 428}, "RightTop": {"X": 901, "Y": 428}, "RightBottom": {"X": 901, "Y": 450}, "LeftBottom": {"X": 887, "Y": 450}}}, {"Name": "单价", "Value": "87.28", "Polygon": {"LeftTop": {"X": 1020, "Y": 426}, "RightTop": {"X": 1080, "Y": 426}, "RightBottom": {"X": 1080, "Y": 449}, "LeftBottom": {"X": 1020, "Y": 449}}}, {"Name": "金额", "Value": "87.28", "Polygon": {"LeftTop": {"X": 1196, "Y": 426}, "RightTop": {"X": 1254, "Y": 426}, "RightBottom": {"X": 1254, "Y": 449}, "LeftBottom": {"X": 1196, "Y": 449}}}, {"Name": "税率", "Value": "3%", "Polygon": {"LeftTop": {"X": 1373, "Y": 426}, "RightTop": {"X": 1407, "Y": 426}, "RightBottom": {"X": 1407, "Y": 449}, "LeftBottom": {"X": 1373, "Y": 449}}}, {"Name": "税额", "Value": "2.62", "Polygon": {"LeftTop": {"X": 1509, "Y": 426}, "RightTop": {"X": 1556, "Y": 426}, "RightBottom": {"X": 1556, "Y": 449}, "LeftBottom": {"X": 1509, "Y": 449}}}, {"Name": "货物或应税劳务、服务名称", "Value": "客运服务费", "Polygon": {"LeftTop": {"X": 201, "Y": 437}, "RightTop": {"X": 320, "Y": 437}, "RightBottom": {"X": 320, "Y": 463}, "LeftBottom": {"X": 201, "Y": 463}}}, {"Name": "合计金额", "Value": "¥87.28", "Polygon": {"LeftTop": {"X": 1252, "Y": 683}, "RightTop": {"X": 1333, "Y": 683}, "RightBottom": {"X": 1333, "Y": 708}, "LeftBottom": {"X": 1252, "Y": 708}}}, {"Name": "合计税额", "Value": "¥2.62", "Polygon": {"LeftTop": {"X": 1580, "Y": 683}, "RightTop": {"X": 1647, "Y": 683}, "RightBottom": {"X": 1647, "Y": 707}, "LeftBottom": {"X": 1580, "Y": 707}}}, {"Name": "价税合计(大写)", "Value": "捌拾玖圆玖角整", "Polygon": {"LeftTop": {"X": 573, "Y": 730}, "RightTop": {"X": 741, "Y": 730}, "RightBottom": {"X": 741, "Y": 755}, "LeftBottom": {"X": 573, "Y": 755}}}, {"Name": "小写金额", "Value": "¥89.90", "Polygon": {"LeftTop": {"X": 1414, "Y": 731}, "RightTop": {"X": 1495, "Y": 731}, "RightBottom": {"X": 1495, "Y": 754}, "LeftBottom": {"X": 1414, "Y": 754}}}, {"Name": "销售方地址、电话", "Value": "天津经济技术开发区南港工业区综合服务区办公楼", "Polygon": {"LeftTop": {"X": 373, "Y": 860}, "RightTop": {"X": 907, "Y": 860}, "RightBottom": {"X": 907, "Y": 880}, "LeftBottom": {"X": 373, "Y": 880}}}, {"Name": "销售方开户行及账号", "Value": "招商银行股份有限公司天津自由贸易试验区分行122905939910401", "Polygon": {"LeftTop": {"X": 373, "Y": 893}, "RightTop": {"X": 975, "Y": 893}, "RightBottom": {"X": 975, "Y": 914}, "LeftBottom": {"X": 373, "Y": 914}}}, {"Name": "收款人", "Value": "张强", "Polygon": {"LeftTop": {"X": 297, "Y": 934}, "RightTop": {"X": 347, "Y": 934}, "RightBottom": {"X": 347, "Y": 960}, "LeftBottom": {"X": 297, "Y": 960}}}, {"Name": "复核", "Value": "静静", "Polygon": {"LeftTop": {"X": 697, "Y": 934}, "RightTop": {"X": 748, "Y": 934}, "RightBottom": {"X": 748, "Y": 960}, "LeftBottom": {"X": 697, "Y": 960}}}, {"Name": "开票人", "Value": "丽丽", "Polygon": {"LeftTop": {"X": 1081, "Y": 934}, "RightTop": {"X": 1130, "Y": 934}, "RightBottom": {"X": 1130, "Y": 959}, "LeftBottom": {"X": 1081, "Y": 959}}}, {"Name": "省", "Value": "天津市", "Polygon": null}, {"Name": "二维码", "Value": "0", "Polygon": null}, {"Name": "是否有纸质全电票标记", "Value": "0", "Polygon": null}, {"Name": "是否有公司印章", "Value": "0", "Polygon": null}, {"Name": "发票类型", "Value": "增值税电子普通发票", "Polygon": null}, {"Name": "发票消费类型", "Value": "服务", "Polygon": null}, {"Name": "市", "Value": "", "Polygon": null}, {"Name": "购买方地址、电话", "Value": "", "Polygon": null}, {"Name": "购买方开户行及账号", "Value": "", "Polygon": null}, {"Name": "打印发票代码", "Value": "", "Polygon": null}, {"Name": "打印发票号码", "Value": "", "Polygon": null}, {"Name": "备注", "Value": "", "Polygon": null}, {"Name": "联次", "Value": "", "Polygon": null}, {"Name": "是否代开", "Value": "", "Polygon": null}, {"Name": "成品油标志", "Value": "", "Polygon": null}, {"Name": "是否有销项负数标记", "Value": "", "Polygon": null}, {"Name": "车船税", "Value": "", "Polygon": null}, {"Name": "全电号码", "Value": "", "Polygon": null}, {"Name": "发票联名", "Value": "", "Polygon": null}, {"Name": "通行日期止", "Value": "", "Polygon": null}, {"Name": "通行日期起", "Value": "", "Polygon": null}, {"Name": "类型", "Value": "", "Polygon": null}, {"Name": "车牌号", "Value": "", "Polygon": null}, {"Name": "通行费标志", "Value": "", "Polygon": null}, {"Name": "服务类型", "Value": "", "Polygon": null}], "Items": [{"LineNo": "1", "Name": "客运服务费", "Spec": "无", "Unit": "次", "Quantity": "1", "UnitPrice": "87.28", "AmountWithoutTax": "87.28", "TaxRate": "3%", "TaxAmount": "2.62", "TaxClassifyCode": "", "VehicleType": "", "VehicleBrand": "", "DeparturePlace": "", "ArrivalPlace": "", "TransportItemsName": "", "ConstructionPlace": "", "ConstructionName": ""}], "PdfPageSize": 0, "Angle": 0.06036967411637306, "RequestId": "bffbc062-f95a-41ea-8c37-68d45456386e"}
"""
